/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SES210.java
 *
 * Created on 2011-7-5, 13:21:55
 */
package seso;

import org.jdesktop.application.Action;
import javax.swing.*;
import java.awt.*;
import java.io.File;

import java.sql.*;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;

/**
 *
 * @author Administrator
 */
public class SES210A extends MaintDialog {

    public SES210A(javax.swing.JFrame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        masterTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        //if (fEOoTempList.size() > 0) masterTable.setRowSelectionInterval(0, 0);
        setHeaderText();

        isBrowseDialog = true;
        refreshToolsBar();

        setProgTitle("SES210/A*", "Customer Order. Open");
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        paintDialogComponent();
    }

    @Override
    public void refreshTableHeaderField() {
        super.refreshTableHeaderField(masterScrollPane, masterTable, "Style", fldStylePanel, fldStyle);
    }

    @Override
    public void paintTemplateComponent() {
        super.paintTemplateComponent(rDialogDataAeraPanel, rDialogShortcutSeparator, rDialogShortcutExpandSwitch, rDialogShortcutPanel, rDiglogShortcutSettingButton, bottomNavigatorPanel, rNavigatorCloseButton, rNavigatorPrevButton, rNavigatorNextButton, dialogTabbedPanel);
    }

    @Override
    public void paintDialogComponent() {
        int bottomMargin = 70; // bottom margin
        int rightMargin = 13;  //right margin
        masterScrollPane.setSize(rDialogDataAeraPanel.getWidth() - rightMargin, rDialogDataAeraPanel.getHeight() - masterScrollPane.getY() - bottomMargin);
        masterTable.setSize(masterScrollPane.getWidth(), masterScrollPane.getHeight());
        
        refreshShortcutButton();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("AS834;databaseName=M3ERPPU").createEntityManager();
        fEOoTempQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT f FROM FEOoTemp f");
        fEOoTempList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : fEOoTempQuery.getResultList();
        rDialogDataAeraPanel = new seso.RDialogDataAeraPanel();
        fldStylePanel = new seso.RPanel();
        fldStyle = new seso.RTextField();
        jLabel1 = new javax.swing.JLabel();
        bottomNavigatorPanel = new seso.RPanel();
        rNavigatorNextButton = new seso.RNavigatorNextButton();
        rNavigatorPrevButton = new seso.RNavigatorPrevButton();
        rNavigatorCloseButton = new seso.RNavigatorCloseButton();
        masterScrollPane = new seso.RTableScrollPane();
        masterTable = new seso.RTable();
        dialogTabbedPanel = new seso.RPanel();
        rDialogTabbedButton1 = new seso.RDialogTabbedButton();
        rDialogTabbedButton2 = new seso.RDialogTabbedButton();
        rDialogTabbedButton3 = new seso.RDialogTabbedButton();
        rDialogTabbedButton4 = new seso.RDialogTabbedButton();
        rDialogTabbedButton5 = new seso.RDialogTabbedButton();
        rDialogShortcutSeparator = new seso.RDialogShortcutSeparator();
        rDialogShortcutPanel = new seso.RDialogShortcutPanel();
        notifyShortcutButton = new seso.RDialogShortcutButton();
        rDiglogShortcutSettingButton = new seso.RDiglogShortcutSettingButton();
        rDialogShortcutExpandSwitch = new seso.RDialogShortcutExpandSwitch();
        uploadShortcutButton = new seso.RDialogShortcutButton();
        checkShortcutButton = new seso.RDialogShortcutButton();
        exportQuestionShortcutButton = new seso.RDialogShortcutButton();
        checkAndImportShortcutButton = new seso.RDialogShortcutButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N
        getContentPane().setLayout(null);

        rDialogDataAeraPanel.setName("rDialogDataAeraPanel"); // NOI18N
        rDialogDataAeraPanel.setLayout(null);

        fldStylePanel.setName("fldStylePanel"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(seso.SesoApp.class).getContext().getResourceMap(SES210A.class);
        fldStyle.setText(resourceMap.getString("fldStyle.text")); // NOI18N
        fldStyle.setCustomizeAlwaysEditable(true);
        fldStyle.setName("fldStyle"); // NOI18N
        fldStyle.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                fldStyleKeyPressed(evt);
            }
        });
        fldStylePanel.add(fldStyle);
        fldStyle.setBounds(0, 0, 90, 24);

        rDialogDataAeraPanel.add(fldStylePanel);
        fldStylePanel.setBounds(100, 10, 110, 40);

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setForeground(resourceMap.getColor("jLabel1.foreground")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        rDialogDataAeraPanel.add(jLabel1);
        jLabel1.setBounds(15, 25, 80, 15);

        bottomNavigatorPanel.setName("bottomNavigatorPanel"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(seso.SesoApp.class).getContext().getActionMap(SES210A.class, this);
        rNavigatorNextButton.setAction(actionMap.get("rNavigatorNextAction")); // NOI18N
        rNavigatorNextButton.setName("rNavigatorNextButton"); // NOI18N
        bottomNavigatorPanel.add(rNavigatorNextButton);
        rNavigatorNextButton.setBounds(710, 0, 88, 28);

        rNavigatorPrevButton.setName("rNavigatorPrevButton"); // NOI18N
        bottomNavigatorPanel.add(rNavigatorPrevButton);
        rNavigatorPrevButton.setBounds(660, 0, 54, 28);

        rNavigatorCloseButton.setAction(actionMap.get("rNavigatorCloseAction")); // NOI18N
        rNavigatorCloseButton.setName("rNavigatorCloseButton"); // NOI18N
        bottomNavigatorPanel.add(rNavigatorCloseButton);
        rNavigatorCloseButton.setBounds(0, 0, 88, 28);

        rDialogDataAeraPanel.add(bottomNavigatorPanel);
        bottomNavigatorPanel.setBounds(10, 280, 800, 28);

        masterScrollPane.setName("masterScrollPane"); // NOI18N

        masterTable.setAutoCreateRowSorter(true);
        masterTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        masterTable.setName("masterTable"); // NOI18N

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, fEOoTempList, masterTable);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${season}"));
        columnBinding.setColumnName("Season");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${brand}"));
        columnBinding.setColumnName("Brand");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${facility}"));
        columnBinding.setColumnName("Facility");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${quality}"));
        columnBinding.setColumnName("Quality");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${style}"));
        columnBinding.setColumnName("Style");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${color}"));
        columnBinding.setColumnName("Color");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${price}"));
        columnBinding.setColumnName("Price");
        columnBinding.setColumnClass(java.math.BigDecimal.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${quantity1}"));
        columnBinding.setColumnName("Quantity1");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${quantity2}"));
        columnBinding.setColumnName("Quantity2");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${quantity3}"));
        columnBinding.setColumnName("Quantity3");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${quantity4}"));
        columnBinding.setColumnName("Quantity4");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${quantity5}"));
        columnBinding.setColumnName("Quantity5");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${quantity6}"));
        columnBinding.setColumnName("Quantity6");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${quantity7}"));
        columnBinding.setColumnName("Quantity7");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${quantity8}"));
        columnBinding.setColumnName("Quantity8");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${quantity9}"));
        columnBinding.setColumnName("Quantity9");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${quantity10}"));
        columnBinding.setColumnName("Quantity10");
        columnBinding.setColumnClass(Integer.class);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        masterTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                masterTableMouseClicked(evt);
            }
        });
        masterTable.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                masterTableKeyReleased(evt);
            }
        });
        masterScrollPane.setViewportView(masterTable);
        masterTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("masterTable.columnModel.title0")); // NOI18N
        masterTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("masterTable.columnModel.title1")); // NOI18N
        masterTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("masterTable.columnModel.title2")); // NOI18N
        masterTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("masterTable.columnModel.title3")); // NOI18N
        masterTable.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("masterTable.columnModel.title4")); // NOI18N
        masterTable.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("masterTable.columnModel.title5")); // NOI18N
        masterTable.getColumnModel().getColumn(6).setHeaderValue(resourceMap.getString("masterTable.columnModel.title6")); // NOI18N
        masterTable.getColumnModel().getColumn(7).setHeaderValue(resourceMap.getString("masterTable.columnModel.title7")); // NOI18N
        masterTable.getColumnModel().getColumn(8).setHeaderValue(resourceMap.getString("masterTable.columnModel.title8")); // NOI18N
        masterTable.getColumnModel().getColumn(9).setHeaderValue(resourceMap.getString("masterTable.columnModel.title9")); // NOI18N
        masterTable.getColumnModel().getColumn(10).setHeaderValue(resourceMap.getString("masterTable.columnModel.title10")); // NOI18N
        masterTable.getColumnModel().getColumn(11).setHeaderValue(resourceMap.getString("masterTable.columnModel.title11")); // NOI18N
        masterTable.getColumnModel().getColumn(12).setHeaderValue(resourceMap.getString("masterTable.columnModel.title12")); // NOI18N
        masterTable.getColumnModel().getColumn(13).setHeaderValue(resourceMap.getString("masterTable.columnModel.title13")); // NOI18N
        masterTable.getColumnModel().getColumn(14).setHeaderValue(resourceMap.getString("masterTable.columnModel.title14")); // NOI18N
        masterTable.getColumnModel().getColumn(15).setHeaderValue(resourceMap.getString("masterTable.columnModel.title15")); // NOI18N
        masterTable.getColumnModel().getColumn(16).setHeaderValue(resourceMap.getString("masterTable.columnModel.title16")); // NOI18N

        rDialogDataAeraPanel.add(masterScrollPane);
        masterScrollPane.setBounds(10, 60, 800, 90);

        dialogTabbedPanel.setName("dialogTabbedPanel"); // NOI18N

        rDialogTabbedButton1.setName("rDialogTabbedButton1"); // NOI18N
        rDialogTabbedButton1.setText0(resourceMap.getString("rDialogTabbedButton1.text0")); // NOI18N
        rDialogTabbedButton1.setText1(resourceMap.getString("rDialogTabbedButton1.text1")); // NOI18N
        rDialogTabbedButton1.setText2(resourceMap.getString("rDialogTabbedButton1.text2")); // NOI18N
        rDialogTabbedButton1.setText3(resourceMap.getString("rDialogTabbedButton1.text3")); // NOI18N
        dialogTabbedPanel.add(rDialogTabbedButton1);
        rDialogTabbedButton1.setBounds(0, 0, 100, 39);

        rDialogTabbedButton2.setCurrentPanel(false);
        rDialogTabbedButton2.setEnabled(false);
        rDialogTabbedButton2.setName("rDialogTabbedButton2"); // NOI18N
        rDialogTabbedButton2.setText0(resourceMap.getString("rDialogTabbedButton2.text0")); // NOI18N
        rDialogTabbedButton2.setText1(resourceMap.getString("rDialogTabbedButton2.text1")); // NOI18N
        rDialogTabbedButton2.setText2(resourceMap.getString("rDialogTabbedButton2.text2")); // NOI18N
        rDialogTabbedButton2.setText3(resourceMap.getString("rDialogTabbedButton2.text3")); // NOI18N
        dialogTabbedPanel.add(rDialogTabbedButton2);
        rDialogTabbedButton2.setBounds(110, 0, 100, 39);

        rDialogTabbedButton3.setCurrentPanel(false);
        rDialogTabbedButton3.setEnabled(false);
        rDialogTabbedButton3.setName("rDialogTabbedButton3"); // NOI18N
        rDialogTabbedButton3.setText0(resourceMap.getString("rDialogTabbedButton3.text0")); // NOI18N
        rDialogTabbedButton3.setText1(resourceMap.getString("rDialogTabbedButton3.text1")); // NOI18N
        rDialogTabbedButton3.setText2(resourceMap.getString("rDialogTabbedButton3.text2")); // NOI18N
        rDialogTabbedButton3.setText3(resourceMap.getString("rDialogTabbedButton3.text3")); // NOI18N
        dialogTabbedPanel.add(rDialogTabbedButton3);
        rDialogTabbedButton3.setBounds(220, 0, 100, 39);

        rDialogTabbedButton4.setEnabled(false);
        rDialogTabbedButton4.setName("rDialogTabbedButton4"); // NOI18N
        rDialogTabbedButton4.setText0(resourceMap.getString("rDialogTabbedButton4.text0")); // NOI18N
        rDialogTabbedButton4.setText1(resourceMap.getString("rDialogTabbedButton4.text1")); // NOI18N
        rDialogTabbedButton4.setText2(resourceMap.getString("rDialogTabbedButton4.text2")); // NOI18N
        dialogTabbedPanel.add(rDialogTabbedButton4);
        rDialogTabbedButton4.setBounds(330, 0, 100, 39);

        rDialogTabbedButton5.setEnabled(false);
        rDialogTabbedButton5.setName("rDialogTabbedButton5"); // NOI18N
        rDialogTabbedButton5.setText0(resourceMap.getString("rDialogTabbedButton5.text0")); // NOI18N
        rDialogTabbedButton5.setText1(resourceMap.getString("rDialogTabbedButton5.text1")); // NOI18N
        rDialogTabbedButton5.setText2(resourceMap.getString("rDialogTabbedButton5.text2")); // NOI18N
        dialogTabbedPanel.add(rDialogTabbedButton5);
        rDialogTabbedButton5.setBounds(440, 0, 120, 39);

        rDialogDataAeraPanel.add(dialogTabbedPanel);
        dialogTabbedPanel.setBounds(20, 240, 780, 36);

        getContentPane().add(rDialogDataAeraPanel);
        rDialogDataAeraPanel.setBounds(0, 71, 820, 330);

        rDialogShortcutSeparator.setName("rDialogShortcutSeparator"); // NOI18N
        rDialogShortcutSeparator.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                rDialogShortcutSeparatorMouseDragged(evt);
            }
        });
        getContentPane().add(rDialogShortcutSeparator);
        rDialogShortcutSeparator.setBounds(830, 71, 8, 200);

        rDialogShortcutPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        rDialogShortcutPanel.setName("rDialogShortcutPanel"); // NOI18N
        rDialogShortcutPanel.setLayout(null);

        notifyShortcutButton.setAction(actionMap.get("notifyAction")); // NOI18N
        notifyShortcutButton.setText(resourceMap.getString("notifyShortcutButton.text")); // NOI18N
        notifyShortcutButton.setName("notifyShortcutButton"); // NOI18N
        rDialogShortcutPanel.add(notifyShortcutButton);
        notifyShortcutButton.setBounds(10, 115, 120, 20);

        rDiglogShortcutSettingButton.setName("rDiglogShortcutSettingButton"); // NOI18N
        rDialogShortcutPanel.add(rDiglogShortcutSettingButton);
        rDiglogShortcutSettingButton.setBounds(140, 10, 20, 20);

        rDialogShortcutExpandSwitch.setName("rDialogShortcutExpandSwitch"); // NOI18N
        rDialogShortcutExpandSwitch.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                rDialogShortcutExpandSwitchMouseClicked(evt);
            }
        });
        rDialogShortcutPanel.add(rDialogShortcutExpandSwitch);
        rDialogShortcutExpandSwitch.setBounds(160, 60, 8, 145);

        uploadShortcutButton.setAction(actionMap.get("uploadAction")); // NOI18N
        uploadShortcutButton.setText(resourceMap.getString("uploadShortcutButton.text")); // NOI18N
        uploadShortcutButton.setName("uploadShortcutButton"); // NOI18N
        rDialogShortcutPanel.add(uploadShortcutButton);
        uploadShortcutButton.setBounds(10, 40, 120, 20);

        checkShortcutButton.setAction(actionMap.get("checkAction")); // NOI18N
        checkShortcutButton.setText(resourceMap.getString("checkShortcutButton.text")); // NOI18N
        checkShortcutButton.setName("checkShortcutButton"); // NOI18N
        rDialogShortcutPanel.add(checkShortcutButton);
        checkShortcutButton.setBounds(10, 65, 120, 20);

        exportQuestionShortcutButton.setAction(actionMap.get("exportQuestionAction")); // NOI18N
        exportQuestionShortcutButton.setText(resourceMap.getString("exportQuestionShortcutButton.text")); // NOI18N
        exportQuestionShortcutButton.setName("exportQuestionShortcutButton"); // NOI18N
        rDialogShortcutPanel.add(exportQuestionShortcutButton);
        exportQuestionShortcutButton.setBounds(10, 90, 120, 20);

        checkAndImportShortcutButton.setAction(actionMap.get("checkAndImportAction")); // NOI18N
        checkAndImportShortcutButton.setText(resourceMap.getString("checkAndImportShortcutButton.text")); // NOI18N
        checkAndImportShortcutButton.setName("checkAndImportShortcutButton"); // NOI18N
        rDialogShortcutPanel.add(checkAndImportShortcutButton);
        checkAndImportShortcutButton.setBounds(10, 160, 120, 20);

        getContentPane().add(rDialogShortcutPanel);
        rDialogShortcutPanel.setBounds(850, 71, 170, 290);

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void rDialogShortcutExpandSwitchMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rDialogShortcutExpandSwitchMouseClicked
        dialogShortcutExpandSwitchMouseClicked(evt, rDialogShortcutExpandSwitch, rDialogShortcutSeparator);
    }//GEN-LAST:event_rDialogShortcutExpandSwitchMouseClicked

    private void rDialogShortcutSeparatorMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rDialogShortcutSeparatorMouseDragged
        dialogShortcutSeparatorMouseDragged(evt, rDialogShortcutExpandSwitch);
    }//GEN-LAST:event_rDialogShortcutSeparatorMouseDragged

    private void masterTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_masterTableMouseClicked
        refreshShortcutButton();
        setHeaderText();
    }//GEN-LAST:event_masterTableMouseClicked

    private void masterTableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_masterTableKeyReleased
        refreshShortcutButton();
        setHeaderText();
    }//GEN-LAST:event_masterTableKeyReleased

    private void fldStyleKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_fldStyleKeyPressed
        masterTable.setRowFilter(fldStyle.getText());
    }//GEN-LAST:event_fldStyleKeyPressed

    private void refreshShortcutButton() {
        String status = "";
        if (masterTable.getSelectedRow() >= 0) {
            status = masterTable.getValueAt(masterTable.getSelectedRow(), 1).toString().trim();
        }
        uploadShortcutButton.setEnabled(masterTable.getSelectedRow() >= 0 && status.equals("Preliminary"));
        checkShortcutButton.setEnabled(masterTable.getSelectedRow() >= 0 && (status.equals("Uploaded") || status.equals("WithQuestion") || status.equals("CheckPassed") ));
        exportQuestionShortcutButton.setEnabled(masterTable.getSelectedRow() >= 0 && status.equals("WithQuestion"));
        notifyShortcutButton.setEnabled(masterTable.getSelectedRow() >= 0 && status.equals("CheckPassed"));
        //importCOShortcutButton.setEnabled(masterTable.getSelectedRow() >= 0 && status.equals("Notified"));
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                SES210A dialog = new SES210A(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    @Override
    public void cmdChangeAction() {
        super.cmdChangeAction();
        rNavigatorNextAction();
    }

    @Override
    public void cmdDisplayAction() {
        super.cmdDisplayAction();
        rNavigatorNextAction();
    }

    @Action
    public void rNavigatorCloseAction() {
        this.cmdCloseAction();
    }

    @Action
    public void rNavigatorNextAction() {
        if (dlgDataMode != AppSetting.CREATE_MODE && masterTable.getSelectedRowCount() == 0) {
            return;
        }
        String transactionNo;

        if (dlgDataMode == AppSetting.CREATE_MODE) {
            transactionNo = fldStyle.getText().trim().toUpperCase();
        } else {
            transactionNo = masterTable.getValueAt(masterTable.getSelectedRow(), 0).toString();
        }

        SES100E dlg = new SES100E(parent, false, transactionNo, dlgDataMode);
        //SES100F dlg = new SES100F(parent, false, transactionNo, dlgDataMode);
        //SES100G dlg = new SES100G(parent, false, transactionNo, dlgDataMode);
        //SES100H dlg = new SES100H(parent, false, transactionNo, dlgDataMode);
        dlg.setMiniProgListJPanel(miniProgListJPanel, indexMiniProgID);

        //dlg.setPrevDialog(this);
        //setVisible(false);
        dispose();

        SesoApp.getApplication().show(dlg);
    }

    @Override
    public void cmdRefreshAction() {
        super.cmdRefreshAction();

        java.util.Collection data = fEOoTempQuery.getResultList();
        for (Object entity : data) {
            entityManager.refresh(entity);
        }
        fEOoTempList.clear();
        fEOoTempList.addAll(data);

        refreshShortcutButton();
    }

    @Override
    public void cmdCreateAction() {
        super.cmdCreateAction();

        String transactionNO = fldStyle.getText().trim().toUpperCase();

        String connectionUrl = "jdbc:sqlserver://M3G;databaseName=M3ERP;user=sa;password=sentserver";
        Connection con = null;
        Statement stmt = null;
        String SQL;

        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            con = DriverManager.getConnection(connectionUrl);

            stmt = con.createStatement();

            SQL = "INSERT INTO FEOoTemp (TransactionNo) VALUES ('" + transactionNO + "')";
            stmt.execute(SQL);

        } catch (Exception exp) {
            exp.printStackTrace();
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (Exception e) {
                }
            }
            if (con != null) {
                try {
                    con.close();
                } catch (Exception e) {
                }
            }
        }

        rNavigatorNextAction();
    }

    private void cmdSave() {
        entityManager.getTransaction().begin();
        for (int i = 0; i < fEOoTempList.size(); i++) {
            entityManager.persist(fEOoTempList.get(i));
        }
        entityManager.getTransaction().commit();
    }

    @Action
    public void notifyAction() {
        if (masterTable.getSelectedRow() < 0) {
            return;
        }
        masterTable.setValueAt("Notified", masterTable.getSelectedRow(), 1);
        cmdSave();
        refreshShortcutButton();
        JOptionPane.showMessageDialog(null, "Notified", "", JOptionPane.INFORMATION_MESSAGE);
    }

    @Action
    public void uploadAction() {
        if (masterTable.getSelectedRow() < 0) {
            return;
        }

        /*
        String transactionNo = masterTable.getValueAt(masterTable.getSelectedRow(), 0).toString().trim();
        if (transactionNo.isEmpty()) {
        return;
        }
        String fldOrderFileDirectory = masterTable.getValueAt(masterTable.getSelectedRow(), 7).toString().trim();
        if (!(new File(fldOrderFileDirectory)).exists()) {
        JOptionPane.showMessageDialog(null, "Directory NOT exist : " + fldOrderFileDirectory);
        return;
        }
        
        String fromDirectory = masterTable.getValueAt(masterTable.getSelectedRow(), 7).toString().trim();
        String toDirectory = AppSetting.TEXTCO_ROOT_DIRECTORY + transactionNo;
        
        RCopyDirectoryDialog dlg = new RCopyDirectoryDialog(fromDirectory, toDirectory);
        
        SesoApp.getApplication().show(dlg);
         *
         */


        String transactionNo = masterTable.getValueAt(masterTable.getSelectedRow(), 0).toString().trim();

        if (transactionNo.isEmpty()) {
            return;
        }

        String fldOrderFileDirectory = masterTable.getValueAt(masterTable.getSelectedRow(), 8).toString().trim();
        if (!(new File(fldOrderFileDirectory)).exists()) {
            JOptionPane.showMessageDialog(null, "Directory NOT exist");
            return;
        }

        String cmd = "D:\\sesotask\\importtxtco.exe " + transactionNo;
        Runtime rn = Runtime.getRuntime();
        Process process = null;
        try {
            process = rn.exec(cmd);
        } catch (Exception ignore) {
            return;
        }

        masterTable.setValueAt("Uploaded", masterTable.getSelectedRow(), 1);
        cmdSave();
        refreshShortcutButton();
        JOptionPane.showMessageDialog(null, "Uploaded", "", JOptionPane.INFORMATION_MESSAGE);
    }

    @Action
    public void checkAction() {

        if (masterTable.getSelectedRow() < 0) {
            return;
        }
        String transactionNO = masterTable.getValueAt(masterTable.getSelectedRow(), 0).toString();

        String connectionUrl = AppSetting.DATABASE_M3ERP_CONNECTION_URL;

        Connection con = null;
        Statement stmt = null;

        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            con = DriverManager.getConnection(connectionUrl);

            String SQL = "M3ERP..usp_CheckEOT '" + transactionNO + "'";
            stmt = con.createStatement();
            stmt.execute(SQL);
        } catch (Exception exp) {
            exp.printStackTrace();
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (Exception e) {
                }
            }
            if (con != null) {
                try {
                    con.close();
                } catch (Exception e) {
                }
            }
        }

        cmdRefreshAction();
        JOptionPane.showMessageDialog(null, "Checked");        
    }

    @Action
    public void checkAndImportAction() {
        if (masterTable.getSelectedRow() < 0) {
            return;
        }
        
        String transactionNo = masterTable.getValueAt(masterTable.getSelectedRow(), 0).toString();

        /*
        SES110B dlg = new SES110B(parent, false, transactionNo, dlgDataMode);
        dlg.setMiniProgListJPanel(miniProgListJPanel, indexMiniProgID);

        dlg.setPrevDialog(this);
        setVisible(false);
        //dispose();

        SesoApp.getApplication().show(dlg);
         * 
         */
        
        this.cmdCloseAction();
        
        SES110B dlg = new SES110B(parent, false, transactionNo, AppSetting.DISPLAY_MODE);
        dlg.setMiniProgListJPanel(miniProgListJPanel, indexMiniProgID);
        SesoApp.getApplication().show(dlg);         
    }

    @Action
    public void exportQuestionAction() {
        boolean result = true;
        
        if (masterTable.getSelectedRow() < 0) {
            return;
        }
        String transactionNo = masterTable.getValueAt(masterTable.getSelectedRow(), 0).toString();

        try {
            (new File("C:/M3Export")).mkdir();
        } catch (Exception exp) {
            JOptionPane.showMessageDialog(null, "Exception : " + exp.getMessage(), "", JOptionPane.ERROR_MESSAGE);
            return;
        }

        String fileName = "C:\\M3Export\\CO Data With Question - " + transactionNo.trim() + ".XLS";
        if (!ExcelFileTools.createExcelFile(fileName, "TempSheet", 0)) {            
            return;
        }

        Connection conExcel = null;
        Statement stmExcel = null;
        String sqlExcel = "";

        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            conExcel = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};ReadOnly=False;DBQ=" + fileName);
            stmExcel = conExcel.createStatement();
            
            sqlExcel = "CREATE TABLE [Summary] (Season char(5), Quality char(15), Style char(15), Color char(15), Size char(15))";
            stmExcel.execute(sqlExcel);
            sqlExcel = "CREATE TABLE [Detail] (TransactionLine char(1), RvPoNo char(1), OrderType char(1), Location char(1), Country char(1), Season char(1), Quality char(1), Style char(1), Color char(1), Size char(1), Quantity int)";
            stmExcel.execute(sqlExcel);
            
        } catch (Exception exp) {
            result = false;
            JOptionPane.showMessageDialog(null, "Exception : " + exp.getMessage(), "", JOptionPane.ERROR_MESSAGE);
        }

        if (!result) {
            try {
                if (stmExcel != null) {
                    stmExcel.close();
                }
            } catch (Exception exp) {
            }
            try {
                if (conExcel != null) {
                    conExcel.close();
                }
            } catch (Exception exp) {
            }
            return;
        }

        String connectionUrl = AppSetting.DATABASE_M3ERP_CONNECTION_URL;
        Connection con = null;
        Statement stmt = null, stmtDetail = null;
        ResultSet rs = null, rsDetail = null;
        String SQL;

        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            con = DriverManager.getConnection(connectionUrl);
            stmt = con.createStatement();
            stmtDetail = con.createStatement();

            // Summary
            SQL = "Select Season, M3Quality, M3Style, M3Color, SizeList "
                    + " from EuropeOrderText  "
                    + " Where TransactionNo = '" + transactionNo + "' and ErrorMessage > ''"
                    + " Group by Season, M3Quality, M3Style, M3Color, SizeList  "
                    + " Order by Season, M3Quality, M3Style, M3Color, SizeList";

            rs = stmt.executeQuery(SQL);
            while (rs.next()) {
                sqlExcel = "Insert into [Summary] (Season, Quality, Style, Color, Size) values ("
                        + "'" + rs.getString(1).trim() + "', "
                        + "'" + rs.getString(2).trim() + "', "
                        + "'" + rs.getString(3).trim() + "', "
                        + "'" + rs.getString(4).trim() + "', "
                        + "'" + rs.getString(5).trim() + "' "
                        + ")";
                stmExcel.execute(sqlExcel);
            }

            // Detail
            SQL = "Select TransNoLine, RvPoNo, OrderType, CustomerDigitalCode, RvSubCustomerCode, Season, M3Quality, M3Style, M3Color, SizeList, Quantity "
                    + " from EuropeOrderText  "
                    + " Where TransactionNo = '" + transactionNo + "' and ErrorMessage > ''"
                    + " Order by TransNoLine";

            rsDetail = stmtDetail.executeQuery(SQL);
            while (rsDetail.next()) {
                
                sqlExcel = "Insert into [Detail] (TransactionLine, RvPoNo, OrderType, Location, Country, Season, Quality, Style, Color, Size, Quantity) values ("
                        + "'" + rsDetail.getString(1).trim() + "', "
                        + "'" + rsDetail.getString(2).trim() + "', "
                        + "'" + rsDetail.getString(3).trim() + "', "
                        + "'" + rsDetail.getString(4).trim() + "', "
                        + "'" + rsDetail.getString(5).trim() + "', "
                        + "'" + rsDetail.getString(6).trim() + "', "
                        + "'" + rsDetail.getString(7).trim() + "', "
                        + "'" + rsDetail.getString(8).trim() + "', "
                        + "'" + rsDetail.getString(9).trim() + "', "
                        + "'" + rsDetail.getString(10).trim() + "', "
                        + rsDetail.getInt(11)
                        + ")";
                stmExcel.execute(sqlExcel);
            }

        } catch (Exception exp) {
            result = false;
            JOptionPane.showMessageDialog(null, "Exception : " + exp.getMessage(), "", JOptionPane.ERROR_MESSAGE);
        } finally {

            if (rs != null) {
                try {
                    rs.close();
                } catch (Exception e) {
                }
            }
            if (rsDetail != null) {
                try {
                    rsDetail.close();
                } catch (Exception e) {
                }
            }
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (Exception e) {
                }
            }
            if (stmtDetail != null) {
                try {
                    stmtDetail.close();
                } catch (Exception e) {
                }
            }
            if (con != null) {
                try {
                    con.close();
                } catch (Exception e) {
                }
            }
        }

        try {
            if (stmExcel != null) {
                stmExcel.close();
            }
        } catch (Exception exp) {
        }
        try {
            if (conExcel != null) {
                conExcel.close();
            }
        } catch (Exception exp) {
        }
        
        ExcelFileTools.removeExcelSheet(fileName, 0);
        
        if (result) {
            JOptionPane.showMessageDialog(null, "Exported to " + fileName, "", JOptionPane.INFORMATION_MESSAGE);
        }        
    }
    
    private void setHeaderText(){   
        if (masterTable.getSelectedRow() > 0) {
            masterTable.getColumnModel().getColumn(7).setHeaderValue(fEOoTempList.get(masterTable.getSelectedRow()).getSize1()); // NOI18N
            masterTable.getColumnModel().getColumn(8).setHeaderValue(fEOoTempList.get(masterTable.getSelectedRow()).getSize2()); // NOI18N
            masterTable.getColumnModel().getColumn(9).setHeaderValue(fEOoTempList.get(masterTable.getSelectedRow()).getSize3()); // NOI18N
            masterTable.getColumnModel().getColumn(10).setHeaderValue(fEOoTempList.get(masterTable.getSelectedRow()).getSize4()); // NOI18N
            masterTable.getColumnModel().getColumn(11).setHeaderValue(fEOoTempList.get(masterTable.getSelectedRow()).getSize5()); // NOI18N
            masterTable.getColumnModel().getColumn(12).setHeaderValue(fEOoTempList.get(masterTable.getSelectedRow()).getSize6()); // NOI18N
            masterTable.getColumnModel().getColumn(13).setHeaderValue(fEOoTempList.get(masterTable.getSelectedRow()).getSize7()); // NOI18N
            masterTable.getColumnModel().getColumn(14).setHeaderValue(fEOoTempList.get(masterTable.getSelectedRow()).getSize8()); // NOI18N
            masterTable.getColumnModel().getColumn(15).setHeaderValue(fEOoTempList.get(masterTable.getSelectedRow()).getSize9()); // NOI18N
            masterTable.getColumnModel().getColumn(16).setHeaderValue(fEOoTempList.get(masterTable.getSelectedRow()).getSize10()); // NOI18N

            masterTable.getTableHeader().repaint();
        }
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private seso.RPanel bottomNavigatorPanel;
    private seso.RDialogShortcutButton checkAndImportShortcutButton;
    private seso.RDialogShortcutButton checkShortcutButton;
    private seso.RPanel dialogTabbedPanel;
    private javax.persistence.EntityManager entityManager;
    private seso.RDialogShortcutButton exportQuestionShortcutButton;
    private java.util.List<seso.FEOoTemp> fEOoTempList;
    private javax.persistence.Query fEOoTempQuery;
    private seso.RTextField fldStyle;
    private seso.RPanel fldStylePanel;
    private javax.swing.JLabel jLabel1;
    private seso.RTableScrollPane masterScrollPane;
    private seso.RTable masterTable;
    private seso.RDialogShortcutButton notifyShortcutButton;
    private seso.RDialogDataAeraPanel rDialogDataAeraPanel;
    private seso.RDialogShortcutExpandSwitch rDialogShortcutExpandSwitch;
    private seso.RDialogShortcutPanel rDialogShortcutPanel;
    private seso.RDialogShortcutSeparator rDialogShortcutSeparator;
    private seso.RDialogTabbedButton rDialogTabbedButton1;
    private seso.RDialogTabbedButton rDialogTabbedButton2;
    private seso.RDialogTabbedButton rDialogTabbedButton3;
    private seso.RDialogTabbedButton rDialogTabbedButton4;
    private seso.RDialogTabbedButton rDialogTabbedButton5;
    private seso.RDiglogShortcutSettingButton rDiglogShortcutSettingButton;
    private seso.RNavigatorCloseButton rNavigatorCloseButton;
    private seso.RNavigatorNextButton rNavigatorNextButton;
    private seso.RNavigatorPrevButton rNavigatorPrevButton;
    private seso.RDialogShortcutButton uploadShortcutButton;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
